<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;

/* @var $this yii\web\View */
/* @var $model backend\models\LogoAdvSearch */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="logo-adv-search">

    <?php $form = ActiveForm::begin([
        'action' => ['index'],
        'method' => 'get',
        'options' => ['class' => 'form-inline'],
    ]); ?>

    <?= $form->field($model, 'adv_name') ?>

    <?= $form->field($model, 'recommend_starttime')->widget(DateTimePicker::className(), 
        [
        'template'=>"{input}{reset}{button}",
        'clientOptions' => [
            'autoclose' => true,
            'linkFormat' => 'yyyy-MM-dd', // if inline = true
            //'format' => 'yyyy-mm-dd', // if inline = false
            'todayBtn' => true,
            'pickerPosition'=>"bottom-left",
            'language'=>'zh-CN',
            'minView'=>'hour'
        ]    
    ]) ?>
     
    ～
     
     <?= $form->field($model, 'recommend_endtime')->widget(DateTimePicker::className(), 
        [
        'template'=>"{input}{reset}{button}",
        'clientOptions' => [
            'autoclose' => true,
            'linkFormat' => 'yyyy-MM-dd', // if inline = true
            //'format' => 'yyyy-mm-dd', // if inline = false
            'todayBtn' => true,
            'pickerPosition'=>"bottom-left",
            'language'=>'zh-CN',
            'minView'=>'hour'
        ]    
    ]) ?>
    <?= $form->field($model, 'tag_display')->dropDownList(['' => '全部', '不显示', '显示']) ?>
    <?= $form->field($model, 'status')->dropDownList(['' => '全部', '不显示', '显示']) ?>
    <?php // echo $form->field($model, 'url') ?>

    <?php // echo $form->field($model, 'status') ?>

    <?php // echo $form->field($model, 'recommend_starttime') ?>

    <?php // echo $form->field($model, 'recommend_endtime') ?>

    <?php // echo $form->field($model, 'add_user') ?>

    <?php // echo $form->field($model, 'add_time') ?>

    <div class="form-group">
        <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
        <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('js');?>
<script>
$(function(){
    $('.form-group').eq(3).attr('style','position:relative;top:-5px;');

    //刷新缓存
    $("#hc").click(function(){
        $.post("<?=Yii::$app->urlManager->createUrl('logo-adv/refresh-cache')?>",{ rnd:Math.random()},  function(json) {
               if(json.flag == 1)
               {
                   alert('刷新成功');
                   return false;
               }
            },"json");
    });
    
    $('#w0').submit(function(){
        var start_time = $('#logoadvsearch-recommend_starttime').val();
        var end_time = $('#logoadvsearch-recommend_endtime').val();
        if((start_time != '' &&  end_time == '') || (start_time == '' &&  end_time != ''))
        {
            alert('开始和结束时间必须全选');
            return false;
        }
        var start=new Date(start_time.replace("-", "/").replace("-", "/"));  
        var end=new Date(end_time.replace("-", "/").replace("-", "/"));  
        if(end<=start){  
            alert('开始必须小于结束时间');
            return false;
        }  
        return true;
    });
});


function checkEndTime(){  
    var startTime=$("#startTime").val();  
    var start=new Date(startTime.replace("-", "/").replace("-", "/"));  
    var endTime=$("#endTime").val();  
    var end=new Date(endTime.replace("-", "/").replace("-", "/"));  
    if(end<start){  
        return false;  
    }  
    return true;  
}  
</script>
<?php $this->endBlock(); ?>
